﻿

//初始化
if (typeof ($) != "undefined") {
    $("#trBillTypeID").hide();
    $("#trVacationID").hide();
    $("#BillCode").attr("disabled", true).css("background", "whitesmoke");

    var fun = getPar1("fun");
    var billtype = getPar1("billtype");
    switch (billtype) {
        case "TRIP":
            break;
        case "OVERTIMELEAVE":
            break;
        case "OVERTIME":
            break;
        case "LEAVE":
            $("#trVacationID").show();
            break;
        default:
            break;
    }

    $(document).ready(function () {
        //获取提报人employeeId
        YAHOO.util.Connect.asyncRequest('POST', "../EHR/GetCurrentUser.aspx", {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str != "-1") {
                        var token = str.split('_');
                        instance[0].EditWho = token[0];
                    }
                }
                catch (e) {
                }
                finally {

                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);

        //获取单据类型ID
        YAHOO.util.Connect.asyncRequest('POST', "../EHR/workTimeAjax.aspx?flag=billid&billtype=" + billtype, {
            success: function (res) {
                try {
                    //debugger;
                    var str = res.responseText;
                    if (str != "-1") {
                        var token = str.split('|');
                        var tokenFirst = token[0].split('_');
                        var tokenSecond = token[1].split('_');
                        //instance[0].BillTypeID = tokenFirst[0];
                        if (fun == "add") {
                            //单据类型ID
                            $("#BillTypeID").val(tokenFirst[0]);
                            //生成单据编码
                            $("#BillCode").val(tokenSecond[0]);
                        }
                    }
                }
                catch (e) { }
                finally { }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);

    });
    instance[0].EditDate = new Date();
    //debugger;
    if (fun == "edit") {
        //$("div button").hide();
    }
    if (fun == "view") {
        //parent.document.getElementById("yui-gen7-button").style.display = "none";
        parent.setButtonHiden();
        $("div input").attr("disabled", true).css("background", "whitesmoke");
        $("div select").attr("disabled", true).css("background", "whitesmoke");
        $("div button").hide();
        setTimeout(HideButton,200);
    }
}

function HideButton() {
    $("#wkEmployeeWorkBill thead:first-child").hide();    
}

//选择员工
var employeeId;
var ValueChanged = function (rowobj) { 
    employeeId = $("#empId").val();
}

var TextChanged = function (rowobj) {
    var employeeName = $("#txtempId").val();
    if (employeeId == "" || employeeId == "undefined") {
        return;
    }
    if (employeeName == "" || employeeName == "undefined") {
        return;
    }
    //debugger
    $("#txtEmployeeID", rowobj).val(employeeName);
    $("#EmployeeID", rowobj).val(employeeId);
    GetDeptNameByEmpID(employeeId);
    GetPostNameByEmpID(employeeId);
    GetEmpcodeByEmpID(employeeId);
}

//获取员工所属部门名称
function GetDeptNameByEmpID(empId) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
    $.get(url, function (d, s) {
        //debugger;
        var list = eval("(" + d + ")");
        //debugger
        for (var o in list.rows) {
            var t = list.rows[o].DeptName;
            if (typeof (t) != "undefined") {
                $("#DeptName", rowobj).val(t);
            }
        }
    });
}

//获取员工所属岗位名称
function GetPostNameByEmpID(empId) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        for (var o in list.rows) {
            var t = list.rows[o].PostName;
            if (typeof (t) != "undefined") {
                $("#PostName", rowobj).val(t);
            }
        }
    });
}

//获取员工编号
function GetEmpcodeByEmpID(empId) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");

        for (var o in list.rows) {
            var t = list.rows[o].EmployeeCode;
            if (typeof (t) != "undefined") {
                $("#EmployeeCode", rowobj).val(t);
            }
        }

    });
}

var fnCheckData = function () {
    try {

        if ($("#BeginWorkDate").val() == "") {
            return "开始日期不能为空！";
        }
        if ($("#BeginTime").val() == "") {
            return "开始时间不能为空！";
        }
        if ($("#EndWorkDate").val() == "") {
            return "结束日期不能为空！";
        }
        if ($("#EndTime").val() == "") {
            return "结束日期不能为空！";
        }
        if ($("#TimeLength").val() == "") {
            return "时长不能为空！";
        }

        var ss = $("#BeginWorkDate").val();
        if (!isDateFormat(ss)) {
            return "开始日期输入错误！";
        }
        ss = $("#EndWorkDate").val();
        if (!isDateFormat(ss)) {
            return "结束日期输入错误！";
        }

        var tempTime = $("#BeginTime").val() + ":01";
        if (!isTime(tempTime)) {
            return "开始时间格式不对!";
        }
        tempTime = $("#EndTime").val() + ":01";
        if (!isTime(tempTime)) {
            return "结束时间格式不对!";
        }
        var reg = /^\d+(\.\d+)?$/;
        if (reg.test($("#TimeLength").val()) == false) {
            return "时长需要输入非零数字!";
        }
    }
    catch (e)
     { }
}

 